package com.example.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.pojo.Goods;
import com.example.mapper.GoodsMapper;
import com.example.service.IGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.vo.ResultVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * <p>
 * 物品表 服务实现类
 * </p>
 *
 * @author wsl
 * @since 2022-04-11
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {

    @Override
    public PageInfo<Goods> selectGoods(Integer gs_classify_id,Integer enabled,String name,Integer num,Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Goods> list = baseMapper.selectGoods(gs_classify_id,enabled,name,num,pageNum,pageSize);
        return new PageInfo<>(list);
    }


    //查询物品主表和物品详细表信息
    @Override
    public List<Goods> querygoods() {
        return baseMapper.querygoods();
    }

    @Override
    public ResultVo addGoods(Goods goods) {
        int i = baseMapper.insert(goods);
        return i > 0 ? ResultVo.success("新增成功") : ResultVo.error("新增失败");
    }

    @Override
    public Boolean hasSameCodeGs(Integer id, String code) {
        QueryWrapper<Goods> wrapper = new QueryWrapper<>();
        wrapper.eq("code",code)
                .notIn(id!=null,"id",id);
        List<Goods> goods = baseMapper.selectList(wrapper);
        return goods.size()>0;
    }
}
